package forum.communication;

import java.util.Date;

import forum.server.controller.ForumFacadeInt;
import forum.server.domain.Gender;
import forum.server.exceptions.*;

/**
 @author Tamir 
 *
 */
public class RegisterMessage extends ClientMessage {

	private static final long serialVersionUID = -3267419208356408002L;
	
	private String username;
	private String password;
	@SuppressWarnings("unused")
    private String firstName;
    @SuppressWarnings("unused")
    private String lastName;
    @SuppressWarnings("unused")
    private String email;
    @SuppressWarnings("unused")
    private Gender gender;
    @SuppressWarnings("unused")
    private String city;
    @SuppressWarnings("unused")
	private Date birthday;

	public RegisterMessage(String username, String password, String firstName, String lastName, String email,Gender gender, String city, Date birthday) {
		this.username = username;
		this.password = password;
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
		this.gender = gender;
		this.city = city;
		this.birthday =	birthday;	
	}

	/* (non-Javadoc)
	 * @see forum.tcpcommunicationlayer.ClientMessage#doOperation(forum.server.domainlayer.ForumFacade)
	 */
	@Override
	public ServerResponse doOperation(ForumFacadeInt forum) {
		try {
			forum.register(this.username, this.password);
			return new ServerResponse("Successfully registered \""+this.username+"\"",true);
		} catch (RegistrationException e) {
			return new ServerResponse(e.getMessage(),false);
		} catch (DatabaseException e) {
			return new ServerResponse("The server is currently down for maintanance.\nPlease try again later.",false);
		}
		
	}

}
